package com.hippy.lib.utils

import android.widget.Toast
import java.lang.Exception

object ToastUtils {
    private const val NULL = "null"

    fun showLong(resId: Int) {
        show(resId, Toast.LENGTH_LONG)
    }

    fun showShort(resId: Int) {
        show(resId, Toast.LENGTH_SHORT)
    }

    fun showLong(text: CharSequence?) {
        show(text, Toast.LENGTH_LONG)
    }

    fun showShort(text: CharSequence?) {
        show(text, Toast.LENGTH_SHORT)
    }

    private fun show(resId: Int, duration: Int) {
        try {
            show(Utils.context.resources.getText(resId), duration)
        } catch (e: Exception) {
            show(resId.toString(), duration)
        }
    }

    private fun show(text: CharSequence?, duration: Int) {
        Toast.makeText(Utils.context, text ?: NULL, duration).show()
    }
}